#pragma once

#include <iostream>
#include <pthread.h>

namespace ns_task
{
    class Task
    {
    private:
        int _x;
        int _y;
        char _op; //+-*/%
    public:
        Task() //消费者获取任务使用无参构造
        {}
        Task(int x, int y, char op) //生产者消费任务需要有参构造
            : _x(x), _y(y), _op(op)
        {}
        int Run()
        {
            int res = 0;
            switch (_op)
            {
            case '+':
                res = _x + _y;
                break;
            case '-':
                res = _x - _y;
                break;
            case '*':
                res = _x * _y;
                break;
            case '/':
                res = _x / _y;
                break;
            case '%':
                res = _x % _y;
                break;
            default:
                std::cout << "错误读取！" << std::endl;
                break;
            }
            std::cout << "线程[" << pthread_self() << "]正在处理任务：" 
            << _x << _op << _y << "=" << res << std::endl;
            return res;
        }
        int operator()()
        {
            return Run();
        }
        ~Task()
        {}
    };
}